// #define CPPHTTPLIB_OPENSSL_SUPPORT
#include "httplib.h"
#include <nlohmann/json.hpp>

int main(void)
{
  // HTTP
  httplib::Server svr;

  // HTTPS
  // httplib::SSLServer svr;

  svr.Get("/:z/:x/:y", [](const httplib::Request &req, httplib::Response &res)
  {
    //httplib解析URL参数按照从后向前的顺序进行
    auto it = req.path_params.begin();
    int y = atoi((it++)->second.c_str());
    int x = atoi((it++)->second.c_str());
    int z = atoi((it++)->second.c_str());
    //res.set_content("Hello World!", "text/plain");
    //res.set_header("Content-Type", "application/json; charset=utf-8");
    //json的赋值也可以写成v["XX"]=xx;
    nlohmann::json json_data;
    for (const auto p : req.path_params)
    {
      json_data[p.first] = p.second;
    }   
    //nlohmann::json json_data = {{"data", "数据"}, {"data2", 123}};
    std::string data = json_data.dump();
    res.set_content(data, "application/json; charset=utf-8");
  });

  svr.listen("0.0.0.0", 8080);
}
